package com.taikang.common.util;

import java.security.MessageDigest;

public class MD5Utils {

	private static String byte2hex(byte[] b) {
		String hs = "";
		String stmp = "";

		for (int n = 0; n < b.length; n++) {
			stmp = Integer.toHexString(b[n] & 0XFF);
			if (stmp.length() == 1)
				hs = hs + "0" + stmp;
			else
				hs = hs + stmp;

			// if (n<b.length-1) hs=hs+":";
		}
		return hs.toUpperCase();
	}

	public static String md5(String value) {
		try {
			MessageDigest md5 = MessageDigest.getInstance("MD5");
			md5.update(value.getBytes("UTF-8"));

			byte[] guid = md5.digest();

			return (byte2hex(guid));

		} catch (Exception e) {
			return null;
		}

	}
	
	public static String getDefaultPassword() {
		return md5("123");
	}
	
	
	public static boolean stringEqual(String befMd5,String afMd5){
		if(md5(befMd5).equals(afMd5)||befMd5.equals(afMd5)){
			return true;
		}
		return false;
	}
	
	public static void main(String[] args){
		System.out.println(md5("123"));
	}
}
